package com.wxxymaker.controller;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.annotation.Param;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.PostRoute;
import com.blade.mvc.ui.RestResponse;
import com.wxxymaker.model.entity.Visitor;
import com.wxxymaker.service.VisitorService;
import io.github.biezhi.anima.page.Page;

import java.util.List;

/**
 * @AUTHOR soft
 * @DATE 2018/8/16 19:42
 * @DESCRIBE 访客浏览记录
 */
@Path(value = "/visitor", restful = true)
public class VisitorController {
    @Inject
    private VisitorService service;

    @PostRoute("/page")
    public RestResponse page(@Param(defaultValue = "1") int no,
                             @Param String time) {
        Page<Visitor> list = service.list(no, time);
        if (list != null && list.getTotalRows() > 0) {
            return RestResponse.ok(list);
        }
        return RestResponse.fail();
    }

    @PostRoute("/times")
    public RestResponse times() {
        List<String> times = service.times();
        if (!times.isEmpty()) {
            return RestResponse.ok(times);
        }
        return RestResponse.fail();
    }
}
